package com.sangmo.boot.auth.core.repo;

import com.sangmo.boot.auth.core.model.AuthorizeCode;
import com.sangmo.boot.framework.data.repo.IRepo;
import com.sangmo.boot.framework.plugin.dataview.spi.jpa.IJpaDataViewRepo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface AuthorizeCodeRepo extends IJpaDataViewRepo<AuthorizeCode> {
    AuthorizeCode findOneByClientIdAndUsername(String clientId, String username);

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Query("UPDATE AuthorizeCode SET failure = failure + 1 WHERE id = :id")
    @Modifying
    void increaseFailure(@Param("id")Long id);
}
